package cn.com.ddapp.ddm.ui.mine;

import android.content.Intent;
import android.os.Bundle;
import android.text.Editable;
import android.text.TextWatcher;
import android.view.View;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.TextView;
import butterknife.BindView;
import butterknife.ButterKnife;
import cn.com.ddapp.ddm.R;
import cn.com.ddapp.ddm.base.BaseActivity;
import cn.com.ddapp.ddm.base.BaseApplication;

public class NickNameActivity extends BaseActivity {


    @BindView(R.id.titletext)
    TextView titletext;
    @BindView(R.id.right_btn)
    ImageView rightBtn;
    @BindView(R.id.right_text)
    TextView rightText;
    @BindView(R.id.view)
    View view;
    @BindView(R.id.nickname_et)
    EditText nicknameEt;

    private String nickName;
    String name ;

    @Override
    public void initView() {
        setTitle(R.string.writename);
        setTitleLeftImg(R.mipmap.back_icon);
        rightText.setText(R.string.end);
        rightText.setVisibility(View.VISIBLE);
        rightText.setTextColor(getResources().getColor(R.color.title_color));
    }

    @Override
    public void initData() {
        nicknameEt.addTextChangedListener(new TextWatcher() {
            @Override
            public void beforeTextChanged(CharSequence charSequence, int i, int i1, int i2) {
            }

            @Override
            public void onTextChanged(CharSequence charSequence, int i, int i1, int i2) {
            }

            @Override
            public void afterTextChanged(Editable editable) {
                nickName = nicknameEt.getText().toString();
            }
        });

        Intent intent = getIntent();
        name = intent.getStringExtra("userName");
        rightText.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Intent intent = new Intent();
                if (nickName.equals("")){
                    BaseApplication.showToast("请输入昵称");
                } else {
                    intent.putExtra("nickName",nickName);
                    setResult(0x188,intent);
                    finish();
                }
            }
        });

    }

    @Override
    public int getContentViewId() {
        return R.layout.activity_nick_name;
    }

    @Override
    protected String getFragmentTag() {
        return null;
    }

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        ButterKnife.bind(this);
    }

    @Override
    protected void onResume() {
        super.onResume();
        nicknameEt.setText(name);
        nicknameEt.setSelection(name.length());
    }
}
